using System;
using System.Data;
using System.Data.SqlClient;
using System.Xml;

namespace WIT.Global;

/// <summary>
/// SqlServer帮助类
/// </summary>
public sealed class MSSQLHelper
{
	/// <summary>  
	/// 枚举,标识数据库连接是由SqlHelper提供还是由调用者提供  
	/// </summary>  
	private enum SqlConnectionOwnership
	{
		/// <summary>由SqlHelper提供连接</summary>  
		Internal,
		/// <summary>由调用者提供连接</summary>  
		External
	}

	private MSSQLHelper()
	{
	}

	/// <summary>  
	/// 将SqlParameter参数数组(参数值)分配给SqlCommand命令.  
	/// 这个方法将给任何一个参数分配DBNull.Value;  
	/// 该操作将阻止默认值的使用.  
	/// </summary>SqlHelperSqlHelper  
	/// <param>命令名</param>  
	/// <param>SqlParameters数组</param>  
	private static void AttachParameters(SqlCommand command, SqlParameter[] commandParameters)
	{
		if (command == null)
		{
			throw new ArgumentNullException("command");
		}
		if (commandParameters == null)
		{
			return;
		}
		foreach (SqlParameter sqlParameter in commandParameters)
		{
			if (sqlParameter != null)
			{
				if ((sqlParameter.Direction == ParameterDirection.InputOutput || sqlParameter.Direction == ParameterDirection.Input) && sqlParameter.Value == null)
				{
					sqlParameter.Value = DBNull.Value;
				}
				command.Parameters.Add(sqlParameter);
			}
		}
	}

	/// <summary>  
	/// 将DataRow类型的列值分配到SqlParameter参数数组.  
	/// </summary>  
	/// <param>要分配值的SqlParameter参数数组</param>  
	/// <param>将要分配给存储过程参数的DataRow</param>  
	private static void AssignParameterValues(SqlParameter[] commandParameters, DataRow dataRow)
	{
		if (commandParameters == null || dataRow == null)
		{
			return;
		}
		int num = 0;
		foreach (SqlParameter sqlParameter in commandParameters)
		{
			if (sqlParameter.ParameterName == null || sqlParameter.ParameterName.Length <= 1)
			{
				throw new Exception($"请提供参数{num}一个有效的名称{sqlParameter.ParameterName}.");
			}
			if (dataRow.Table.Columns.IndexOf(sqlParameter.ParameterName.Substring(1)) != -1)
			{
				sqlParameter.Value = dataRow[sqlParameter.ParameterName.Substring(1)];
			}
			num++;
		}
	}

	/// <summary>  
	/// 将一个对象数组分配给SqlParameter参数数组.  
	/// </summary>  
	/// <param>要分配值的SqlParameter参数数组</param>  
	/// <param>将要分配给存储过程参数的对象数组</param>  
	private static void AssignParameterValues(SqlParameter[] commandParameters, object[] parameterValues)
	{
		if (commandParameters == null || parameterValues == null)
		{
			return;
		}
		if (commandParameters.Length != parameterValues.Length)
		{
			throw new ArgumentException("参数值个数与参数不匹配.");
		}
		int i = 0;
		for (int num = commandParameters.Length; i < num; i++)
		{
			if (parameterValues[i] is IDbDataParameter)
			{
				IDbDataParameter dbDataParameter = (IDbDataParameter)parameterValues[i];
				if (dbDataParameter.Value == null)
				{
					commandParameters[i].Value = DBNull.Value;
				}
				else
				{
					commandParameters[i].Value = dbDataParameter.Value;
				}
			}
			else if (parameterValues == null)
			{
				commandParameters[i].Value = DBNull.Value;
			}
			else
			{
				commandParameters[i].Value = parameterValues[i];
			}
		}
	}

	/// <summary>  
	/// 预处理用户提供的命令,数据库连接/事务/命令类型/参数  
	/// </summary>  
	/// <param>要处理的SqlCommand</param>  
	/// <param>数据库连接</param>  
	/// <param>一个有效的事务或者是null值</param>  
	/// <param>命令类型 (存储过程,命令文本, 其它.)</param>  
	/// <param>存储过程名或都T-SQL命令文本</param>  
	/// <param>和命令相关联的SqlParameter参数数组,如果没有参数为'null'</param>  
	/// <param><c>true</c> 如果连接是打开的,则为true,其它情况下为false.</param>  
	private static void PrepareCommand(SqlCommand command, SqlConnection connection, SqlTransaction transaction, CommandType commandType, string commandText, SqlParameter[] commandParameters, out bool mustCloseConnection)
	{
		if (command == null)
		{
			throw new ArgumentNullException("command");
		}
		if (commandText == null || commandText.Length == 0)
		{
			throw new ArgumentNullException("commandText");
		}
		if (connection.State != ConnectionState.Open)
		{
			mustCloseConnection = true;
			connection.Open();
		}
		else
		{
			mustCloseConnection = false;
		}
		command.Connection = connection;
		command.CommandText = commandText;
		if (transaction != null)
		{
			if (transaction.Connection == null)
			{
				throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");
			}
			command.Transaction = transaction;
		}
		command.CommandType = commandType;
		if (commandParameters != null)
		{
			AttachParameters(command, commandParameters);
		}
	}

	/// <summary>  
	/// 执行指定连接字符串,类型的SqlCommand.  
	/// </summary>  
	/// <remarks>  
	/// 示例:    
	///  int result = ExecuteNonQuery(connString, CommandType.StoredProcedure, "PublishOrders");  
	/// </remarks>  
	/// <param>一个有效的数据库连接字符串</param>  
	/// <param>命令类型 (存储过程,命令文本, 其它.)</param>  
	/// <param>存储过程名称或SQL语句</param>  
	/// <returns>返回命令影响的行数</returns>  
	public static int ExecuteNonQuery(string connectionString, CommandType commandType, string commandText)
	{
		return ExecuteNonQuery(connectionString, commandType, commandText, (SqlParameter[])null);
	}

	/// <summary>  
	/// 执行指定连接字符串,类型的SqlCommand.如果没有提供参数,不返回结果.  
	/// </summary>  
	/// <remarks>  
	/// 示例:    
	///  int result = ExecuteNonQuery(connString, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));  
	/// </remarks>  
	/// <param>一个有效的数据库连接字符串</param>  
	/// <param>命令类型 (存储过程,命令文本, 其它.)</param>  
	/// <param>存储过程名称或SQL语句</param>  
	/// <param>SqlParameter参数数组</param>  
	/// <returns>返回命令影响的行数</returns>  
	public static int ExecuteNonQuery(string connectionString, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
	{
		if (connectionString == null || connectionString.Length == 0)
		{
			throw new ArgumentNullException("connectionString");
		}
		using SqlConnection sqlConnection = new SqlConnection(connectionString);
		sqlConnection.Open();
		return ExecuteNonQuery(sqlConnection, commandType, commandText, commandParameters);
	}

	/// <summary>
	/// 执行指定连接字符串的存储过程,将对象数组的值赋给存储过程参数,此方法需要在参数缓存方法中探索参数并生成参数. 这个方法没有提供访问输出参数和返回值.
	/// 示例: int result = ExecuteNonQuery(connString, "PublishOrders", 24, 36);  
	/// </summary>
	/// <param name="connectionString">一个有效的数据库连接字符串</param>
	/// <param name="spName">存储过程名称</param>
	/// <param name="parameterValues">分配到存储过程输入参数的对象数组</param>
	/// <returns>返回受影响的行数</returns>
	public static int ExecuteNonQuery(string connectionString, string spName, params object[] parameterValues)
	{
		if (connectionString == null || connectionString.Length == 0)
		{
			throw new ArgumentNullException("connectionString");
		}
		if (spName == null || spName.Length == 0)
		{
			throw new ArgumentNullException("spName");
		}
		if (parameterValues != null && parameterValues.Length != 0)
		{
			SqlParameter[] spParameterSet = SqlHelperParameterCache.GetSpParameterSet(connectionString, spName);
			AssignParameterValues(spParameterSet, parameterValues);
			return ExecuteNonQuery(connectionString, CommandType.StoredProcedure, spName, spParameterSet);
		}
		return ExecuteNonQuery(connectionString, CommandType.StoredProcedure, spName);
	}

	/// <summary>  
	/// 执行指定数据库连接对象的命令   
	/// </summary>  
	/// <remarks>  
	/// 示例:    
	///  int result = ExecuteNonQuery(conn, CommandType.StoredProcedure, "PublishOrders");  
	/// </remarks>  
	/// <param>一个有效的数据库连接对象</param>  
	/// <param>命令类型(存储过程,命令文本或其它.)</param>  
	/// <param>存储过程名称或T-SQL语句</param>  
	/// <returns>返回影响的行数</returns>  
	public static int ExecuteNonQuery(SqlConnection connection, CommandType commandType, string commandText)
	{
		return ExecuteNonQuery(connection, commandType, commandText, (SqlParameter[])null);
	}

	/// <summary>  
	/// 执行指定数据库连接对象的命令  
	/// </summary>  
	/// <remarks>  
	/// 示例:    
	///  int result = ExecuteNonQuery(conn, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));  
	/// </remarks>  
	/// <param>一个有效的数据库连接对象</param>  
	/// <param>命令类型(存储过程,命令文本或其它.)</param>  
	/// <param>T存储过程名称或T-SQL语句</param>  
	/// <param>SqlParamter参数数组</param>  
	/// <returns>返回影响的行数</returns>  
	public static int ExecuteNonQuery(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
	{
		if (connection == null)
		{
			throw new ArgumentNullException("connection");
		}
		SqlCommand sqlCommand = new SqlCommand();
		bool mustCloseConnection = false;
		PrepareCommand(sqlCommand, connection, null, commandType, commandText, commandParameters, out mustCloseConnection);
		int result = sqlCommand.ExecuteNonQuery();
		sqlCommand.Parameters.Clear();
		if (mustCloseConnection)
		{
			connection.Close();
		}
		return result;
	}

	/// <summary>  
	/// 执行指定数据库连接对象的命令,将对象数组的值赋给存储过程参数.  
	/// </summary>  
	/// <remarks>  
	/// 此方法不提供访问存储过程输出参数和返回值  
	/// 示例:    
	///  int result = ExecuteNonQuery(conn, "PublishOrders", 24, 36);  
	/// </remarks>  
	/// <param>一个有效的数据库连接对象</param>  
	/// <param>存储过程名</param>  
	/// <param>分配给存储过程输入参数的对象数组</param>  
	/// <returns>返回影响的行数</returns>  
	public static int ExecuteNonQuery(SqlConnection connection, string spName, params object[] parameterValues)
	{
		if (connection == null)
		{
			throw new ArgumentNullException("connection");
		}
		if (spName == null || spName.Length == 0)
		{
			throw new ArgumentNullException("spName");
		}
		if (parameterValues != null && parameterValues.Length != 0)
		{
			SqlParameter[] spParameterSet = SqlHelperParameterCache.GetSpParameterSet(connection, spName);
			AssignParameterValues(spParameterSet, parameterValues);
			return ExecuteNonQuery(connection, CommandType.StoredProcedure, spName, spParameterSet);
		}
		return ExecuteNonQuery(connection, CommandType.StoredProcedure, spName);
	}

	/// <summary>
	/// 执行带事务的SqlCommand.
	/// 示例: int result = ExecuteNonQuery(trans, CommandType.StoredProcedure, "PublishOrders");  
	/// </summary>
	/// <param name="transaction">一个有效的数据库连接对象</param>
	/// <param name="commandType">命令类型(存储过程,命令文本或其它.)</param>
	/// <param name="commandText">存储过程名称或T-SQL语句</param>
	/// <returns>返回影响的行数</returns>
	public static int ExecuteNonQuery(SqlTransaction transaction, CommandType commandType, string commandText)
	{
		return ExecuteNonQuery(transaction, commandType, commandText, (SqlParameter[])null);
	}

	/// <summary>  
	/// 执行带事务的SqlCommand(指定参数).  
	/// </summary>  
	/// <remarks>  
	/// 示例:    
	///  int result = ExecuteNonQuery(trans, CommandType.StoredProcedure, "GetOrders", new SqlParameter("@prodid", 24));  
	/// </remarks>  
	/// <param>一个有效的数据库连接对象</param>  
	/// <param>命令类型(存储过程,命令文本或其它.)</param>  
	/// <param>存储过程名称或T-SQL语句</param>  
	/// <param>SqlParamter参数数组</param>  
	/// <returns>返回影响的行数</returns>  
	public static int ExecuteNonQuery(SqlTransaction transaction, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
	{
		if (transaction == null)
		{
			throw new ArgumentNullException("transaction");
		}
		if (transaction != null && transaction.Connection == null)
		{
			throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");
		}
		SqlCommand sqlCommand = new SqlCommand();
		bool mustCloseConnection = false;
		PrepareCommand(sqlCommand, transaction.Connection, transaction, commandType, commandText, commandParameters, out mustCloseConnection);
		int result = sqlCommand.ExecuteNonQuery();
		sqlCommand.Parameters.Clear();
		return result;
	}

	/// <summary>  
	/// 执行带事务的SqlCommand(指定参数值).  
	/// </summary>  
	/// <remarks>  
	/// 此方法不提供访问存储过程输出参数和返回值  
	/// 示例:    
	///  int result = ExecuteNonQuery(conn, trans, "PublishOrders", 24, 36);  
	/// </remarks>  
	/// <param>一个有效的数据库连接对象</param>  
	/// <param>存储过程名</param>  
	/// <param>分配给存储过程输入参数的对象数组</param>  
	/// <returns>返回受影响的行数</returns>  
	public static int ExecuteNonQuery(SqlTransaction transaction, string spName, params object[] parameterValues)
	{
		if (transaction == null)
		{
			throw new ArgumentNullException("transaction");
		}
		if (transaction != null && transaction.Connection == null)
		{
			throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");
		}
		if (spName == null || spName.Length == 0)
		{
			throw new ArgumentNullException("spName");
		}
		if (parameterValues != null && parameterValues.Length != 0)
		{
			SqlParameter[] spParameterSet = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection, spName);
			AssignParameterValues(spParameterSet, parameterValues);
			return ExecuteNonQuery(transaction, CommandType.StoredProcedure, spName, spParameterSet);
		}
		return ExecuteNonQuery(transaction, CommandType.StoredProcedure, spName);
	}

	/// <summary>  
	/// 执行指定数据库连接字符串的命令,返回DataSet.  
	/// </summary>  
	/// <remarks>  
	/// 示例:    
	///  DataSet ds = ExecuteDataset(connString, CommandType.StoredProcedure, "GetOrders");  
	/// </remarks>  
	/// <param>一个有效的数据库连接字符串</param>  
	/// <param>命令类型 (存储过程,命令文本或其它)</param>  
	/// <param>存储过程名称或T-SQL语句</param>  
	/// <returns>返回一个包含结果集的DataSet</returns>  
	public static DataSet ExecuteDataset(string connectionString, CommandType commandType, string commandText)
	{
		return ExecuteDataset(connectionString, commandType, commandText, (SqlParameter[])null);
	}

	/// <summary>  
	/// 执行指定数据库连接字符串的命令,返回DataSet.  
	/// </summary>  
	/// <remarks>  
	/// 示例:   
	///  DataSet ds = ExecuteDataset(connString, CommandType.StoredProcedure, "GetOrders", new SqlParameter("@prodid", 24));  
	/// </remarks>  
	/// <param>一个有效的数据库连接字符串</param>  
	/// <param>命令类型 (存储过程,命令文本或其它)</param>  
	/// <param>存储过程名称或T-SQL语句</param>  
	/// <param>SqlParamters参数数组</param>  
	/// <returns>返回一个包含结果集的DataSet</returns>  
	public static DataSet ExecuteDataset(string connectionString, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
	{
		if (connectionString == null || connectionString.Length == 0)
		{
			throw new ArgumentNullException("connectionString");
		}
		using SqlConnection sqlConnection = new SqlConnection(connectionString);
		sqlConnection.Open();
		return ExecuteDataset(sqlConnection, commandType, commandText, commandParameters);
	}

	/// <summary>  
	/// 执行指定数据库连接字符串的命令,直接提供参数值,返回DataSet.  
	/// </summary>  
	/// <remarks>  
	/// 此方法不提供访问存储过程输出参数和返回值.  
	/// 示例:   
	///  DataSet ds = ExecuteDataset(connString, "GetOrders", 24, 36);  
	/// </remarks>  
	/// <param>一个有效的数据库连接字符串</param>  
	/// <param>存储过程名</param>  
	/// <param>分配给存储过程输入参数的对象数组</param>  
	/// <returns>返回一个包含结果集的DataSet</returns>  
	public static DataSet ExecuteDataset(string connectionString, string spName, params object[] parameterValues)
	{
		if (connectionString == null || connectionString.Length == 0)
		{
			throw new ArgumentNullException("connectionString");
		}
		if (spName == null || spName.Length == 0)
		{
			throw new ArgumentNullException("spName");
		}
		if (parameterValues != null && parameterValues.Length != 0)
		{
			SqlParameter[] spParameterSet = SqlHelperParameterCache.GetSpParameterSet(connectionString, spName);
			AssignParameterValues(spParameterSet, parameterValues);
			return ExecuteDataset(connectionString, CommandType.StoredProcedure, spName, spParameterSet);
		}
		return ExecuteDataset(connectionString, CommandType.StoredProcedure, spName);
	}

	/// <summary>  
	/// 执行指定数据库连接对象的命令,返回DataSet.  
	/// </summary>  
	/// <remarks>  
	/// 示例:    
	///  DataSet ds = ExecuteDataset(conn, CommandType.StoredProcedure, "GetOrders");  
	/// </remarks>  
	/// <param>一个有效的数据库连接对象</param>  
	/// <param>命令类型 (存储过程,命令文本或其它)</param>  
	/// <param>存储过程名或T-SQL语句</param>  
	/// <returns>返回一个包含结果集的DataSet</returns>  
	public static DataSet ExecuteDataset(SqlConnection connection, CommandType commandType, string commandText)
	{
		return ExecuteDataset(connection, commandType, commandText, (SqlParameter[])null);
	}

	/// <summary>  
	/// 执行指定数据库连接对象的命令,指定存储过程参数,返回DataSet.  
	/// </summary>  
	/// <remarks>  
	/// 示例:    
	///  DataSet ds = ExecuteDataset(conn, CommandType.StoredProcedure, "GetOrders", new SqlParameter("@prodid", 24));  
	/// </remarks>  
	/// <param>一个有效的数据库连接对象</param>  
	/// <param>命令类型 (存储过程,命令文本或其它)</param>  
	/// <param>存储过程名或T-SQL语句</param>  
	/// <param>SqlParamter参数数组</param>  
	/// <returns>返回一个包含结果集的DataSet</returns>  
	public static DataSet ExecuteDataset(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
	{
		if (connection == null)
		{
			throw new ArgumentNullException("connection");
		}
		SqlCommand sqlCommand = new SqlCommand();
		bool mustCloseConnection = false;
		PrepareCommand(sqlCommand, connection, null, commandType, commandText, commandParameters, out mustCloseConnection);
		using SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand);
		DataSet dataSet = new DataSet();
		sqlDataAdapter.Fill(dataSet);
		sqlCommand.Parameters.Clear();
		if (mustCloseConnection)
		{
			connection.Close();
		}
		return dataSet;
	}

	/// <summary>  
	/// 执行指定数据库连接对象的命令,指定参数值,返回DataSet.  
	/// </summary>  
	/// <remarks>  
	/// 此方法不提供访问存储过程输入参数和返回值.  
	/// 示例.:    
	///  DataSet ds = ExecuteDataset(conn, "GetOrders", 24, 36);  
	/// </remarks>  
	/// <param>一个有效的数据库连接对象</param>  
	/// <param>存储过程名</param>  
	/// <param>分配给存储过程输入参数的对象数组</param>  
	/// <returns>返回一个包含结果集的DataSet</returns>  
	public static DataSet ExecuteDataset(SqlConnection connection, string spName, params object[] parameterValues)
	{
		if (connection == null)
		{
			throw new ArgumentNullException("connection");
		}
		if (spName == null || spName.Length == 0)
		{
			throw new ArgumentNullException("spName");
		}
		if (parameterValues != null && parameterValues.Length != 0)
		{
			SqlParameter[] spParameterSet = SqlHelperParameterCache.GetSpParameterSet(connection, spName);
			AssignParameterValues(spParameterSet, parameterValues);
			return ExecuteDataset(connection, CommandType.StoredProcedure, spName, spParameterSet);
		}
		return ExecuteDataset(connection, CommandType.StoredProcedure, spName);
	}

	/// <summary>  
	/// 执行指定事务的命令,返回DataSet.  
	/// </summary>  
	/// <remarks>  
	/// 示例:    
	///  DataSet ds = ExecuteDataset(trans, CommandType.StoredProcedure, "GetOrders");  
	/// </remarks>  
	/// <param>事务</param>  
	/// <param>命令类型 (存储过程,命令文本或其它)</param>  
	/// <param>存储过程名或T-SQL语句</param>  
	/// <returns>返回一个包含结果集的DataSet</returns>  
	public static DataSet ExecuteDataset(SqlTransaction transaction, CommandType commandType, string commandText)
	{
		return ExecuteDataset(transaction, commandType, commandText, (SqlParameter[])null);
	}

	/// <summary>  
	/// 执行指定事务的命令,指定参数,返回DataSet.  
	/// </summary>  
	/// <remarks>  
	/// 示例:    
	///  DataSet ds = ExecuteDataset(trans, CommandType.StoredProcedure, "GetOrders", new SqlParameter("@prodid", 24));  
	/// </remarks>  
	/// <param>事务</param>  
	/// <param>命令类型 (存储过程,命令文本或其它)</param>  
	/// <param>存储过程名或T-SQL语句</param>  
	/// <param>SqlParamter参数数组</param>  
	/// <returns>返回一个包含结果集的DataSet</returns>  
	public static DataSet ExecuteDataset(SqlTransaction transaction, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
	{
		if (transaction == null)
		{
			throw new ArgumentNullException("transaction");
		}
		if (transaction != null && transaction.Connection == null)
		{
			throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");
		}
		SqlCommand sqlCommand = new SqlCommand();
		bool mustCloseConnection = false;
		PrepareCommand(sqlCommand, transaction.Connection, transaction, commandType, commandText, commandParameters, out mustCloseConnection);
		using SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand);
		DataSet dataSet = new DataSet();
		sqlDataAdapter.Fill(dataSet);
		sqlCommand.Parameters.Clear();
		return dataSet;
	}

	/// <summary>  
	/// 执行指定事务的命令,指定参数值,返回DataSet.  
	/// </summary>  
	/// <remarks>  
	/// 此方法不提供访问存储过程输入参数和返回值.  
	/// 示例.:    
	///  DataSet ds = ExecuteDataset(trans, "GetOrders", 24, 36);  
	/// </remarks>  
	/// <param>事务</param>  
	/// <param>存储过程名</param>  
	/// <param>分配给存储过程输入参数的对象数组</param>  
	/// <returns>返回一个包含结果集的DataSet</returns>  
	public static DataSet ExecuteDataset(SqlTransaction transaction, string spName, params object[] parameterValues)
	{
		if (transaction == null)
		{
			throw new ArgumentNullException("transaction");
		}
		if (transaction != null && transaction.Connection == null)
		{
			throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");
		}
		if (spName == null || spName.Length == 0)
		{
			throw new ArgumentNullException("spName");
		}
		if (parameterValues != null && parameterValues.Length != 0)
		{
			SqlParameter[] spParameterSet = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection, spName);
			AssignParameterValues(spParameterSet, parameterValues);
			return ExecuteDataset(transaction, CommandType.StoredProcedure, spName, spParameterSet);
		}
		return ExecuteDataset(transaction, CommandType.StoredProcedure, spName);
	}

	/// <summary>  
	/// 执行指定数据库连接对象的数据阅读器.  
	/// </summary>  
	/// <remarks>  
	/// 如果是SqlHelper打开连接,当连接关闭DataReader也将关闭.  
	/// 如果是调用都打开连接,DataReader由调用都管理.  
	/// </remarks>  
	/// <param>一个有效的数据库连接对象</param>  
	/// <param>一个有效的事务,或者为 'null'</param>  
	/// <param>命令类型 (存储过程,命令文本或其它)</param>  
	/// <param>存储过程名或T-SQL语句</param>  
	/// <param>SqlParameters参数数组,如果没有参数则为'null'</param>  
	/// <param>标识数据库连接对象是由调用者提供还是由SqlHelper提供</param>  
	/// <returns>返回包含结果集的SqlDataReader</returns>  
	private static SqlDataReader ExecuteReader(SqlConnection connection, SqlTransaction transaction, CommandType commandType, string commandText, SqlParameter[] commandParameters, SqlConnectionOwnership connectionOwnership)
	{
		if (connection == null)
		{
			throw new ArgumentNullException("connection");
		}
		bool mustCloseConnection = false;
		SqlCommand sqlCommand = new SqlCommand();
		try
		{
			PrepareCommand(sqlCommand, connection, transaction, commandType, commandText, commandParameters, out mustCloseConnection);
			SqlDataReader result = ((connectionOwnership != SqlConnectionOwnership.External) ? sqlCommand.ExecuteReader(CommandBehavior.CloseConnection) : sqlCommand.ExecuteReader());
			bool flag = true;
			foreach (SqlParameter parameter in sqlCommand.Parameters)
			{
				if (parameter.Direction != ParameterDirection.Input)
				{
					flag = false;
				}
			}
			if (flag)
			{
				sqlCommand.Parameters.Clear();
			}
			return result;
		}
		catch
		{
			if (mustCloseConnection)
			{
				connection.Close();
			}
			throw;
		}
	}

	/// <summary>  
	/// 执行指定数据库连接字符串的数据阅读器.  
	/// </summary>  
	/// <remarks>  
	/// 示例:    
	///  SqlDataReader dr = ExecuteReader(connString, CommandType.StoredProcedure, "GetOrders");  
	/// </remarks>  
	/// <param>一个有效的数据库连接字符串</param>  
	/// <param>命令类型 (存储过程,命令文本或其它)</param>  
	/// <param>存储过程名或T-SQL语句</param>  
	/// <returns>返回包含结果集的SqlDataReader</returns>  
	public static SqlDataReader ExecuteReader(string connectionString, CommandType commandType, string commandText)
	{
		return ExecuteReader(connectionString, commandType, commandText, (SqlParameter[])null);
	}

	/// <summary>  
	/// 执行指定数据库连接字符串的数据阅读器,指定参数.  
	/// </summary>  
	/// <remarks>  
	/// 示例:    
	///  SqlDataReader dr = ExecuteReader(connString, CommandType.StoredProcedure, "GetOrders", new SqlParameter("@prodid", 24));  
	/// </remarks>  
	/// <param>一个有效的数据库连接字符串</param>  
	/// <param>命令类型 (存储过程,命令文本或其它)</param>  
	/// <param>存储过程名或T-SQL语句</param>  
	/// <param>SqlParamter参数数组(new SqlParameter("@prodid", 24))</param>  
	/// <returns>返回包含结果集的SqlDataReader</returns>  
	public static SqlDataReader ExecuteReader(string connectionString, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
	{
		if (connectionString == null || connectionString.Length == 0)
		{
			throw new ArgumentNullException("connectionString");
		}
		SqlConnection sqlConnection = null;
		try
		{
			sqlConnection = new SqlConnection(connectionString);
			sqlConnection.Open();
			return ExecuteReader(sqlConnection, null, commandType, commandText, commandParameters, SqlConnectionOwnership.Internal);
		}
		catch
		{
			sqlConnection?.Close();
			throw;
		}
	}

	/// <summary>  
	/// 执行指定数据库连接字符串的数据阅读器,指定参数值.  
	/// </summary>  
	/// <remarks>  
	/// 此方法不提供访问存储过程输出参数和返回值参数.  
	/// 示例:    
	///  SqlDataReader dr = ExecuteReader(connString, "GetOrders", 24, 36);  
	/// </remarks>  
	/// <param>一个有效的数据库连接字符串</param>  
	/// <param>存储过程名</param>  
	/// <param>分配给存储过程输入参数的对象数组</param>  
	/// <returns>返回包含结果集的SqlDataReader</returns>  
	public static SqlDataReader ExecuteReader(string connectionString, string spName, params object[] parameterValues)
	{
		if (connectionString == null || connectionString.Length == 0)
		{
			throw new ArgumentNullException("connectionString");
		}
		if (spName == null || spName.Length == 0)
		{
			throw new ArgumentNullException("spName");
		}
		if (parameterValues != null && parameterValues.Length != 0)
		{
			SqlParameter[] spParameterSet = SqlHelperParameterCache.GetSpParameterSet(connectionString, spName);
			AssignParameterValues(spParameterSet, parameterValues);
			return ExecuteReader(connectionString, CommandType.StoredProcedure, spName, spParameterSet);
		}
		return ExecuteReader(connectionString, CommandType.StoredProcedure, spName);
	}

	/// <summary>  
	/// 执行指定数据库连接对象的数据阅读器.  
	/// </summary>  
	/// <remarks>  
	/// 示例:    
	///  SqlDataReader dr = ExecuteReader(conn, CommandType.StoredProcedure, "GetOrders");  
	/// </remarks>  
	/// <param>一个有效的数据库连接对象</param>  
	/// <param>命令类型 (存储过程,命令文本或其它)</param>  
	/// <param>存储过程名或T-SQL语句</param>  
	/// <returns>返回包含结果集的SqlDataReader</returns>  
	public static SqlDataReader ExecuteReader(SqlConnection connection, CommandType commandType, string commandText)
	{
		return ExecuteReader(connection, commandType, commandText, (SqlParameter[])null);
	}

	/// <summary>  
	/// [调用者方式]执行指定数据库连接对象的数据阅读器,指定参数.  
	/// </summary>  
	/// <remarks>  
	/// 示例:    
	///  SqlDataReader dr = ExecuteReader(conn, CommandType.StoredProcedure, "GetOrders", new SqlParameter("@prodid", 24));  
	/// </remarks>  
	/// <param>一个有效的数据库连接对象</param>  
	/// <param>命令类型 (存储过程,命令文本或其它)</param>  
	/// <param>命令类型 (存储过程,命令文本或其它)</param>  
	/// <param>SqlParamter参数数组</param>  
	/// <returns>返回包含结果集的SqlDataReader</returns>  
	public static SqlDataReader ExecuteReader(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
	{
		return ExecuteReader(connection, null, commandType, commandText, commandParameters, SqlConnectionOwnership.External);
	}

	/// <summary>  
	/// [调用者方式]执行指定数据库连接对象的数据阅读器,指定参数值.  
	/// </summary>  
	/// <remarks>  
	/// 此方法不提供访问存储过程输出参数和返回值参数.  
	/// 示例:    
	///  SqlDataReader dr = ExecuteReader(conn, "GetOrders", 24, 36);  
	/// </remarks>  
	/// <param>一个有效的数据库连接对象</param>  
	/// <param>T存储过程名</param>  
	/// <param>分配给存储过程输入参数的对象数组</param>  
	/// <returns>返回包含结果集的SqlDataReader</returns>  
	public static SqlDataReader ExecuteReader(SqlConnection connection, string spName, params object[] parameterValues)
	{
		if (connection == null)
		{
			throw new ArgumentNullException("connection");
		}
		if (spName == null || spName.Length == 0)
		{
			throw new ArgumentNullException("spName");
		}
		if (parameterValues != null && parameterValues.Length != 0)
		{
			SqlParameter[] spParameterSet = SqlHelperParameterCache.GetSpParameterSet(connection, spName);
			AssignParameterValues(spParameterSet, parameterValues);
			return ExecuteReader(connection, CommandType.StoredProcedure, spName, spParameterSet);
		}
		return ExecuteReader(connection, CommandType.StoredProcedure, spName);
	}

	/// <summary>  
	/// [调用者方式]执行指定数据库事务的数据阅读器,指定参数值.  
	/// </summary>  
	/// <remarks>  
	/// 示例:    
	///  SqlDataReader dr = ExecuteReader(trans, CommandType.StoredProcedure, "GetOrders");  
	/// </remarks>  
	/// <param>一个有效的连接事务</param>  
	/// <param>命令类型 (存储过程,命令文本或其它)</param>  
	/// <param>存储过程名称或T-SQL语句</param>  
	/// <returns>返回包含结果集的SqlDataReader</returns>  
	public static SqlDataReader ExecuteReader(SqlTransaction transaction, CommandType commandType, string commandText)
	{
		return ExecuteReader(transaction, commandType, commandText, (SqlParameter[])null);
	}

	/// <summary>  
	/// [调用者方式]执行指定数据库事务的数据阅读器,指定参数.  
	/// </summary>  
	/// <remarks>  
	/// 示例:    
	///   SqlDataReader dr = ExecuteReader(trans, CommandType.StoredProcedure, "GetOrders", new SqlParameter("@prodid", 24));  
	/// </remarks>  
	/// <param>一个有效的连接事务</param>  
	/// <param>命令类型 (存储过程,命令文本或其它)</param>  
	/// <param>存储过程名称或T-SQL语句</param>  
	/// <param>分配给命令的SqlParamter参数数组</param>  
	/// <returns>返回包含结果集的SqlDataReader</returns>  
	public static SqlDataReader ExecuteReader(SqlTransaction transaction, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
	{
		if (transaction == null)
		{
			throw new ArgumentNullException("transaction");
		}
		if (transaction != null && transaction.Connection == null)
		{
			throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");
		}
		return ExecuteReader(transaction.Connection, transaction, commandType, commandText, commandParameters, SqlConnectionOwnership.External);
	}

	/// <summary>  
	/// [调用者方式]执行指定数据库事务的数据阅读器,指定参数值.  
	/// </summary>  
	/// <remarks>  
	/// 此方法不提供访问存储过程输出参数和返回值参数.  
	///
	/// 示例:    
	///  SqlDataReader dr = ExecuteReader(trans, "GetOrders", 24, 36);  
	/// </remarks>  
	/// <param>一个有效的连接事务</param>  
	/// <param>存储过程名称</param>  
	/// <param>分配给存储过程输入参数的对象数组</param>  
	/// <returns>返回包含结果集的SqlDataReader</returns>  
	public static SqlDataReader ExecuteReader(SqlTransaction transaction, string spName, params object[] parameterValues)
	{
		if (transaction == null)
		{
			throw new ArgumentNullException("transaction");
		}
		if (transaction != null && transaction.Connection == null)
		{
			throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");
		}
		if (spName == null || spName.Length == 0)
		{
			throw new ArgumentNullException("spName");
		}
		if (parameterValues != null && parameterValues.Length != 0)
		{
			SqlParameter[] spParameterSet = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection, spName);
			AssignParameterValues(spParameterSet, parameterValues);
			return ExecuteReader(transaction, CommandType.StoredProcedure, spName, spParameterSet);
		}
		return ExecuteReader(transaction, CommandType.StoredProcedure, spName);
	}

	/// <summary>  
	/// 执行指定数据库连接字符串的命令,返回结果集中的第一行第一列.  
	/// </summary>  
	/// <remarks>  
	/// 示例:    
	///  int orderCount = (int)ExecuteScalar(connString, CommandType.StoredProcedure, "GetOrderCount");  
	/// </remarks>  
	/// <param>一个有效的数据库连接字符串</param>  
	/// <param>命令类型 (存储过程,命令文本或其它)</param>  
	/// <param>存储过程名称或T-SQL语句</param>  
	/// <returns>返回结果集中的第一行第一列</returns>  
	public static object ExecuteScalar(string connectionString, CommandType commandType, string commandText)
	{
		return ExecuteScalar(connectionString, commandType, commandText, (SqlParameter[])null);
	}

	/// <summary>  
	/// 执行指定数据库连接字符串的命令,指定参数,返回结果集中的第一行第一列.  
	/// </summary>  
	/// <remarks>  
	/// 示例:    
	///  int orderCount = (int)ExecuteScalar(connString, CommandType.StoredProcedure, "GetOrderCount", new SqlParameter("@prodid", 24));  
	/// </remarks>  
	/// <param>一个有效的数据库连接字符串</param>  
	/// <param>命令类型 (存储过程,命令文本或其它)</param>  
	/// <param>存储过程名称或T-SQL语句</param>  
	/// <param>分配给命令的SqlParamter参数数组</param>  
	/// <returns>返回结果集中的第一行第一列</returns>  
	public static object ExecuteScalar(string connectionString, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
	{
		if (connectionString == null || connectionString.Length == 0)
		{
			throw new ArgumentNullException("connectionString");
		}
		using SqlConnection sqlConnection = new SqlConnection(connectionString);
		sqlConnection.Open();
		return ExecuteScalar(sqlConnection, commandType, commandText, commandParameters);
	}

	/// <summary>  
	/// 执行指定数据库连接字符串的命令,指定参数值,返回结果集中的第一行第一列.  
	/// </summary>  
	/// <remarks>  
	/// 此方法不提供访问存储过程输出参数和返回值参数.  
	///
	/// 示例:    
	///  int orderCount = (int)ExecuteScalar(connString, "GetOrderCount", 24, 36);  
	/// </remarks>  
	/// <param>一个有效的数据库连接字符串</param>  
	/// <param>存储过程名称</param>  
	/// <param>分配给存储过程输入参数的对象数组</param>  
	/// <returns>返回结果集中的第一行第一列</returns>  
	public static object ExecuteScalar(string connectionString, string spName, params object[] parameterValues)
	{
		if (connectionString == null || connectionString.Length == 0)
		{
			throw new ArgumentNullException("connectionString");
		}
		if (spName == null || spName.Length == 0)
		{
			throw new ArgumentNullException("spName");
		}
		if (parameterValues != null && parameterValues.Length != 0)
		{
			SqlParameter[] spParameterSet = SqlHelperParameterCache.GetSpParameterSet(connectionString, spName);
			AssignParameterValues(spParameterSet, parameterValues);
			return ExecuteScalar(connectionString, CommandType.StoredProcedure, spName, spParameterSet);
		}
		return ExecuteScalar(connectionString, CommandType.StoredProcedure, spName);
	}

	/// <summary>  
	/// 执行指定数据库连接对象的命令,返回结果集中的第一行第一列.  
	/// </summary>  
	/// <remarks>  
	/// 示例:    
	///  int orderCount = (int)ExecuteScalar(conn, CommandType.StoredProcedure, "GetOrderCount");  
	/// </remarks>  
	/// <param>一个有效的数据库连接对象</param>  
	/// <param>命令类型 (存储过程,命令文本或其它)</param>  
	/// <param>存储过程名称或T-SQL语句</param>  
	/// <returns>返回结果集中的第一行第一列</returns>  
	public static object ExecuteScalar(SqlConnection connection, CommandType commandType, string commandText)
	{
		return ExecuteScalar(connection, commandType, commandText, (SqlParameter[])null);
	}

	/// <summary>  
	/// 执行指定数据库连接对象的命令,指定参数,返回结果集中的第一行第一列.  
	/// </summary>  
	/// <remarks>  
	/// 示例:    
	///  int orderCount = (int)ExecuteScalar(conn, CommandType.StoredProcedure, "GetOrderCount", new SqlParameter("@prodid", 24));  
	/// </remarks>  
	/// <param>一个有效的数据库连接对象</param>  
	/// <param>命令类型 (存储过程,命令文本或其它)</param>  
	/// <param>存储过程名称或T-SQL语句</param>  
	/// <param>分配给命令的SqlParamter参数数组</param>  
	/// <returns>返回结果集中的第一行第一列</returns>  
	public static object ExecuteScalar(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
	{
		if (connection == null)
		{
			throw new ArgumentNullException("connection");
		}
		SqlCommand sqlCommand = new SqlCommand();
		bool mustCloseConnection = false;
		PrepareCommand(sqlCommand, connection, null, commandType, commandText, commandParameters, out mustCloseConnection);
		object result = sqlCommand.ExecuteScalar();
		sqlCommand.Parameters.Clear();
		if (mustCloseConnection)
		{
			connection.Close();
		}
		return result;
	}

	/// <summary>  
	/// 执行指定数据库连接对象的命令,指定参数值,返回结果集中的第一行第一列.  
	/// </summary>  
	/// <remarks>  
	/// 此方法不提供访问存储过程输出参数和返回值参数.  
	///
	/// 示例:    
	///  int orderCount = (int)ExecuteScalar(conn, "GetOrderCount", 24, 36);  
	/// </remarks>  
	/// <param>一个有效的数据库连接对象</param>  
	/// <param>存储过程名称</param>  
	/// <param>分配给存储过程输入参数的对象数组</param>  
	/// <returns>返回结果集中的第一行第一列</returns>  
	public static object ExecuteScalar(SqlConnection connection, string spName, params object[] parameterValues)
	{
		if (connection == null)
		{
			throw new ArgumentNullException("connection");
		}
		if (spName == null || spName.Length == 0)
		{
			throw new ArgumentNullException("spName");
		}
		if (parameterValues != null && parameterValues.Length != 0)
		{
			SqlParameter[] spParameterSet = SqlHelperParameterCache.GetSpParameterSet(connection, spName);
			AssignParameterValues(spParameterSet, parameterValues);
			return ExecuteScalar(connection, CommandType.StoredProcedure, spName, spParameterSet);
		}
		return ExecuteScalar(connection, CommandType.StoredProcedure, spName);
	}

	/// <summary>  
	/// 执行指定数据库事务的命令,返回结果集中的第一行第一列.  
	/// </summary>  
	/// <remarks>  
	/// 示例:    
	///  int orderCount = (int)ExecuteScalar(trans, CommandType.StoredProcedure, "GetOrderCount");  
	/// </remarks>  
	/// <param>一个有效的连接事务</param>  
	/// <param>命令类型 (存储过程,命令文本或其它)</param>  
	/// <param>存储过程名称或T-SQL语句</param>  
	/// <returns>返回结果集中的第一行第一列</returns>  
	public static object ExecuteScalar(SqlTransaction transaction, CommandType commandType, string commandText)
	{
		return ExecuteScalar(transaction, commandType, commandText, (SqlParameter[])null);
	}

	/// <summary>  
	/// 执行指定数据库事务的命令,指定参数,返回结果集中的第一行第一列.  
	/// </summary>  
	/// <remarks>  
	/// 示例:    
	///  int orderCount = (int)ExecuteScalar(trans, CommandType.StoredProcedure, "GetOrderCount", new SqlParameter("@prodid", 24));  
	/// </remarks>  
	/// <param>一个有效的连接事务</param>  
	/// <param>命令类型 (存储过程,命令文本或其它)</param>  
	/// <param>存储过程名称或T-SQL语句</param>  
	/// <param>分配给命令的SqlParamter参数数组</param>  
	/// <returns>返回结果集中的第一行第一列</returns>  
	public static object ExecuteScalar(SqlTransaction transaction, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
	{
		if (transaction == null)
		{
			throw new ArgumentNullException("transaction");
		}
		if (transaction != null && transaction.Connection == null)
		{
			throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");
		}
		SqlCommand sqlCommand = new SqlCommand();
		bool mustCloseConnection = false;
		PrepareCommand(sqlCommand, transaction.Connection, transaction, commandType, commandText, commandParameters, out mustCloseConnection);
		object result = sqlCommand.ExecuteScalar();
		sqlCommand.Parameters.Clear();
		return result;
	}

	/// <summary>  
	/// 执行指定数据库事务的命令,指定参数值,返回结果集中的第一行第一列.  
	/// </summary>  
	/// <remarks>  
	/// 此方法不提供访问存储过程输出参数和返回值参数.  
	///
	/// 示例:    
	///  int orderCount = (int)ExecuteScalar(trans, "GetOrderCount", 24, 36);  
	/// </remarks>  
	/// <param>一个有效的连接事务</param>  
	/// <param>存储过程名称</param>  
	/// <param>分配给存储过程输入参数的对象数组</param>  
	/// <returns>返回结果集中的第一行第一列</returns>  
	public static object ExecuteScalar(SqlTransaction transaction, string spName, params object[] parameterValues)
	{
		if (transaction == null)
		{
			throw new ArgumentNullException("transaction");
		}
		if (transaction != null && transaction.Connection == null)
		{
			throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");
		}
		if (spName == null || spName.Length == 0)
		{
			throw new ArgumentNullException("spName");
		}
		if (parameterValues != null && parameterValues.Length != 0)
		{
			SqlParameter[] spParameterSet = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection, spName);
			AssignParameterValues(spParameterSet, parameterValues);
			return ExecuteScalar(transaction, CommandType.StoredProcedure, spName, spParameterSet);
		}
		return ExecuteScalar(transaction, CommandType.StoredProcedure, spName);
	}

	/// <summary>  
	/// 执行指定数据库连接对象的SqlCommand命令,并产生一个XmlReader对象做为结果集返回.  
	/// </summary>  
	/// <remarks>  
	/// 示例:    
	///  XmlReader r = ExecuteXmlReader(conn, CommandType.StoredProcedure, "GetOrders");  
	/// </remarks>  
	/// <param>一个有效的数据库连接对象</param>  
	/// <param>命令类型 (存储过程,命令文本或其它)</param>  
	/// <param>存储过程名称或T-SQL语句 using "FOR XML AUTO"</param>  
	/// <returns>返回XmlReader结果集对象.</returns>  
	public static XmlReader ExecuteXmlReader(SqlConnection connection, CommandType commandType, string commandText)
	{
		return ExecuteXmlReader(connection, commandType, commandText, (SqlParameter[])null);
	}

	/// <summary>  
	/// 执行指定数据库连接对象的SqlCommand命令,并产生一个XmlReader对象做为结果集返回,指定参数.  
	/// </summary>  
	/// <remarks>  
	/// 示例:    
	///  XmlReader r = ExecuteXmlReader(conn, CommandType.StoredProcedure, "GetOrders", new SqlParameter("@prodid", 24));  
	/// </remarks>  
	/// <param>一个有效的数据库连接对象</param>  
	/// <param>命令类型 (存储过程,命令文本或其它)</param>  
	/// <param>存储过程名称或T-SQL语句 using "FOR XML AUTO"</param>  
	/// <param>分配给命令的SqlParamter参数数组</param>  
	/// <returns>返回XmlReader结果集对象.</returns>  
	public static XmlReader ExecuteXmlReader(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
	{
		if (connection == null)
		{
			throw new ArgumentNullException("connection");
		}
		bool mustCloseConnection = false;
		SqlCommand sqlCommand = new SqlCommand();
		try
		{
			PrepareCommand(sqlCommand, connection, null, commandType, commandText, commandParameters, out mustCloseConnection);
			XmlReader result = sqlCommand.ExecuteXmlReader();
			sqlCommand.Parameters.Clear();
			return result;
		}
		catch
		{
			if (mustCloseConnection)
			{
				connection.Close();
			}
			throw;
		}
	}

	/// <summary>  
	/// 执行指定数据库连接对象的SqlCommand命令,并产生一个XmlReader对象做为结果集返回,指定参数值.  
	/// </summary>  
	/// <remarks>  
	/// 此方法不提供访问存储过程输出参数和返回值参数.  
	///
	/// 示例:    
	///  XmlReader r = ExecuteXmlReader(conn, "GetOrders", 24, 36);  
	/// </remarks>  
	/// <param>一个有效的数据库连接对象</param>  
	/// <param>存储过程名称 using "FOR XML AUTO"</param>  
	/// <param>分配给存储过程输入参数的对象数组</param>  
	/// <returns>返回XmlReader结果集对象.</returns>  
	public static XmlReader ExecuteXmlReader(SqlConnection connection, string spName, params object[] parameterValues)
	{
		if (connection == null)
		{
			throw new ArgumentNullException("connection");
		}
		if (spName == null || spName.Length == 0)
		{
			throw new ArgumentNullException("spName");
		}
		if (parameterValues != null && parameterValues.Length != 0)
		{
			SqlParameter[] spParameterSet = SqlHelperParameterCache.GetSpParameterSet(connection, spName);
			AssignParameterValues(spParameterSet, parameterValues);
			return ExecuteXmlReader(connection, CommandType.StoredProcedure, spName, spParameterSet);
		}
		return ExecuteXmlReader(connection, CommandType.StoredProcedure, spName);
	}

	/// <summary>  
	/// 执行指定数据库事务的SqlCommand命令,并产生一个XmlReader对象做为结果集返回.  
	/// </summary>  
	/// <remarks>  
	/// 示例:    
	///  XmlReader r = ExecuteXmlReader(trans, CommandType.StoredProcedure, "GetOrders");  
	/// </remarks>  
	/// <param>一个有效的连接事务</param>  
	/// <param>命令类型 (存储过程,命令文本或其它)</param>  
	/// <param>存储过程名称或T-SQL语句 using "FOR XML AUTO"</param>  
	/// <returns>返回XmlReader结果集对象.</returns>  
	public static XmlReader ExecuteXmlReader(SqlTransaction transaction, CommandType commandType, string commandText)
	{
		return ExecuteXmlReader(transaction, commandType, commandText, (SqlParameter[])null);
	}

	/// <summary>  
	/// 执行指定数据库事务的SqlCommand命令,并产生一个XmlReader对象做为结果集返回,指定参数.  
	/// </summary>  
	/// <remarks>  
	/// 示例:    
	///  XmlReader r = ExecuteXmlReader(trans, CommandType.StoredProcedure, "GetOrders", new SqlParameter("@prodid", 24));  
	/// </remarks>  
	/// <param>一个有效的连接事务</param>  
	/// <param>命令类型 (存储过程,命令文本或其它)</param>  
	/// <param>存储过程名称或T-SQL语句 using "FOR XML AUTO"</param>  
	/// <param>分配给命令的SqlParamter参数数组</param>  
	/// <returns>返回XmlReader结果集对象.</returns>  
	public static XmlReader ExecuteXmlReader(SqlTransaction transaction, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
	{
		if (transaction == null)
		{
			throw new ArgumentNullException("transaction");
		}
		if (transaction != null && transaction.Connection == null)
		{
			throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");
		}
		SqlCommand sqlCommand = new SqlCommand();
		bool mustCloseConnection = false;
		PrepareCommand(sqlCommand, transaction.Connection, transaction, commandType, commandText, commandParameters, out mustCloseConnection);
		XmlReader result = sqlCommand.ExecuteXmlReader();
		sqlCommand.Parameters.Clear();
		return result;
	}

	/// <summary>  
	/// 执行指定数据库事务的SqlCommand命令,并产生一个XmlReader对象做为结果集返回,指定参数值.  
	/// </summary>  
	/// <remarks>  
	/// 此方法不提供访问存储过程输出参数和返回值参数.  
	///
	/// 示例:    
	///  XmlReader r = ExecuteXmlReader(trans, "GetOrders", 24, 36);  
	/// </remarks>  
	/// <param>一个有效的连接事务</param>  
	/// <param>存储过程名称</param>  
	/// <param>分配给存储过程输入参数的对象数组</param>  
	/// <returns>返回一个包含结果集的DataSet.</returns>  
	public static XmlReader ExecuteXmlReader(SqlTransaction transaction, string spName, params object[] parameterValues)
	{
		if (transaction == null)
		{
			throw new ArgumentNullException("transaction");
		}
		if (transaction != null && transaction.Connection == null)
		{
			throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");
		}
		if (spName == null || spName.Length == 0)
		{
			throw new ArgumentNullException("spName");
		}
		if (parameterValues != null && parameterValues.Length != 0)
		{
			SqlParameter[] spParameterSet = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection, spName);
			AssignParameterValues(spParameterSet, parameterValues);
			return ExecuteXmlReader(transaction, CommandType.StoredProcedure, spName, spParameterSet);
		}
		return ExecuteXmlReader(transaction, CommandType.StoredProcedure, spName);
	}

	/// <summary>  
	/// 执行指定数据库连接字符串的命令,映射数据表并填充数据集.  
	/// </summary>  
	/// <remarks>  
	/// 示例:    
	///  FillDataset(connString, CommandType.StoredProcedure, "GetOrders", ds, new string[] {"orders"});  
	/// </remarks>  
	/// <param>一个有效的数据库连接字符串</param>  
	/// <param>命令类型 (存储过程,命令文本或其它)</param>  
	/// <param>存储过程名称或T-SQL语句</param>  
	/// <param>要填充结果集的DataSet实例</param>  
	/// <param>表映射的数据表数组  
	/// 用户定义的表名 (可有是实际的表名.)</param>  
	public static void FillDataset(string connectionString, CommandType commandType, string commandText, DataSet dataSet, string[] tableNames)
	{
		if (connectionString == null || connectionString.Length == 0)
		{
			throw new ArgumentNullException("connectionString");
		}
		if (dataSet == null)
		{
			throw new ArgumentNullException("dataSet");
		}
		using SqlConnection sqlConnection = new SqlConnection(connectionString);
		sqlConnection.Open();
		FillDataset(sqlConnection, commandType, commandText, dataSet, tableNames);
	}

	/// <summary>  
	/// 执行指定数据库连接字符串的命令,映射数据表并填充数据集.指定命令参数.  
	/// </summary>  
	/// <remarks>  
	/// 示例:    
	///  FillDataset(connString, CommandType.StoredProcedure, "GetOrders", ds, new string[] {"orders"}, new SqlParameter("@prodid", 24));  
	/// </remarks>  
	/// <param>一个有效的数据库连接字符串</param>  
	/// <param>命令类型 (存储过程,命令文本或其它)</param>  
	/// <param>存储过程名称或T-SQL语句</param>  
	/// <param>分配给命令的SqlParamter参数数组</param>  
	/// <param>要填充结果集的DataSet实例</param>  
	/// <param>表映射的数据表数组  
	/// 用户定义的表名 (可有是实际的表名.)  
	/// </param>  
	public static void FillDataset(string connectionString, CommandType commandType, string commandText, DataSet dataSet, string[] tableNames, params SqlParameter[] commandParameters)
	{
		if (connectionString == null || connectionString.Length == 0)
		{
			throw new ArgumentNullException("connectionString");
		}
		if (dataSet == null)
		{
			throw new ArgumentNullException("dataSet");
		}
		using SqlConnection sqlConnection = new SqlConnection(connectionString);
		sqlConnection.Open();
		FillDataset(sqlConnection, commandType, commandText, dataSet, tableNames, commandParameters);
	}

	/// <summary>  
	/// 执行指定数据库连接字符串的命令,映射数据表并填充数据集,指定存储过程参数值.  
	/// </summary>  
	/// <remarks>  
	/// 此方法不提供访问存储过程输出参数和返回值参数.  
	///
	/// 示例:    
	///  FillDataset(connString, CommandType.StoredProcedure, "GetOrders", ds, new string[] {"orders"}, 24);  
	/// </remarks>  
	/// <param>一个有效的数据库连接字符串</param>  
	/// <param>存储过程名称</param>  
	/// <param>要填充结果集的DataSet实例</param>  
	/// <param>表映射的数据表数组  
	/// 用户定义的表名 (可有是实际的表名.)  
	/// </param>      
	/// <param>分配给存储过程输入参数的对象数组</param>  
	public static void FillDataset(string connectionString, string spName, DataSet dataSet, string[] tableNames, params object[] parameterValues)
	{
		if (connectionString == null || connectionString.Length == 0)
		{
			throw new ArgumentNullException("connectionString");
		}
		if (dataSet == null)
		{
			throw new ArgumentNullException("dataSet");
		}
		using SqlConnection sqlConnection = new SqlConnection(connectionString);
		sqlConnection.Open();
		FillDataset(sqlConnection, spName, dataSet, tableNames, parameterValues);
	}

	/// <summary>  
	/// 执行指定数据库连接对象的命令,映射数据表并填充数据集.  
	/// </summary>  
	/// <remarks>  
	/// 示例:    
	///  FillDataset(conn, CommandType.StoredProcedure, "GetOrders", ds, new string[] {"orders"});  
	/// </remarks>  
	/// <param>一个有效的数据库连接对象</param>  
	/// <param>命令类型 (存储过程,命令文本或其它)</param>  
	/// <param>存储过程名称或T-SQL语句</param>  
	/// <param>要填充结果集的DataSet实例</param>  
	/// <param>表映射的数据表数组  
	/// 用户定义的表名 (可有是实际的表名.)  
	/// </param>      
	public static void FillDataset(SqlConnection connection, CommandType commandType, string commandText, DataSet dataSet, string[] tableNames)
	{
		FillDataset(connection, commandType, commandText, dataSet, tableNames, (SqlParameter[])null);
	}

	/// <summary>  
	/// 执行指定数据库连接对象的命令,映射数据表并填充数据集,指定参数.  
	/// </summary>  
	/// <remarks>  
	/// 示例:    
	///  FillDataset(conn, CommandType.StoredProcedure, "GetOrders", ds, new string[] {"orders"}, new SqlParameter("@prodid", 24));  
	/// </remarks>  
	/// <param>一个有效的数据库连接对象</param>  
	/// <param>命令类型 (存储过程,命令文本或其它)</param>  
	/// <param>存储过程名称或T-SQL语句</param>  
	/// <param>要填充结果集的DataSet实例</param>  
	/// <param>表映射的数据表数组  
	/// 用户定义的表名 (可有是实际的表名.)  
	/// </param>  
	/// <param>分配给命令的SqlParamter参数数组</param>  
	public static void FillDataset(SqlConnection connection, CommandType commandType, string commandText, DataSet dataSet, string[] tableNames, params SqlParameter[] commandParameters)
	{
		FillDataset(connection, null, commandType, commandText, dataSet, tableNames, commandParameters);
	}

	/// <summary>  
	/// 执行指定数据库连接对象的命令,映射数据表并填充数据集,指定存储过程参数值.  
	/// </summary>  
	/// <remarks>  
	/// 此方法不提供访问存储过程输出参数和返回值参数.  
	///
	/// 示例:    
	///  FillDataset(conn, "GetOrders", ds, new string[] {"orders"}, 24, 36);  
	/// </remarks>  
	/// <param>一个有效的数据库连接对象</param>  
	/// <param>存储过程名称</param>  
	/// <param>要填充结果集的DataSet实例</param>  
	/// <param>表映射的数据表数组  
	/// 用户定义的表名 (可有是实际的表名.)  
	/// </param>  
	/// <param>分配给存储过程输入参数的对象数组</param>  
	public static void FillDataset(SqlConnection connection, string spName, DataSet dataSet, string[] tableNames, params object[] parameterValues)
	{
		if (connection == null)
		{
			throw new ArgumentNullException("connection");
		}
		if (dataSet == null)
		{
			throw new ArgumentNullException("dataSet");
		}
		if (spName == null || spName.Length == 0)
		{
			throw new ArgumentNullException("spName");
		}
		if (parameterValues != null && parameterValues.Length != 0)
		{
			SqlParameter[] spParameterSet = SqlHelperParameterCache.GetSpParameterSet(connection, spName);
			AssignParameterValues(spParameterSet, parameterValues);
			FillDataset(connection, CommandType.StoredProcedure, spName, dataSet, tableNames, spParameterSet);
		}
		else
		{
			FillDataset(connection, CommandType.StoredProcedure, spName, dataSet, tableNames);
		}
	}

	/// <summary>  
	/// 执行指定数据库事务的命令,映射数据表并填充数据集.  
	/// </summary>  
	/// <remarks>  
	/// 示例:    
	///  FillDataset(trans, CommandType.StoredProcedure, "GetOrders", ds, new string[] {"orders"});  
	/// </remarks>  
	/// <param>一个有效的连接事务</param>  
	/// <param>命令类型 (存储过程,命令文本或其它)</param>  
	/// <param>存储过程名称或T-SQL语句</param>  
	/// <param>要填充结果集的DataSet实例</param>  
	/// <param>表映射的数据表数组  
	/// 用户定义的表名 (可有是实际的表名.)  
	/// </param>  
	public static void FillDataset(SqlTransaction transaction, CommandType commandType, string commandText, DataSet dataSet, string[] tableNames)
	{
		FillDataset(transaction, commandType, commandText, dataSet, tableNames, (SqlParameter[])null);
	}

	/// <summary>  
	/// 执行指定数据库事务的命令,映射数据表并填充数据集,指定参数.  
	/// </summary>  
	/// <remarks>  
	/// 示例:    
	///  FillDataset(trans, CommandType.StoredProcedure, "GetOrders", ds, new string[] {"orders"}, new SqlParameter("@prodid", 24));  
	/// </remarks>  
	/// <param>一个有效的连接事务</param>  
	/// <param>命令类型 (存储过程,命令文本或其它)</param>  
	/// <param>存储过程名称或T-SQL语句</param>  
	/// <param>要填充结果集的DataSet实例</param>  
	/// <param>表映射的数据表数组  
	/// 用户定义的表名 (可有是实际的表名.)  
	/// </param>  
	/// <param>分配给命令的SqlParamter参数数组</param>  
	public static void FillDataset(SqlTransaction transaction, CommandType commandType, string commandText, DataSet dataSet, string[] tableNames, params SqlParameter[] commandParameters)
	{
		FillDataset(transaction.Connection, transaction, commandType, commandText, dataSet, tableNames, commandParameters);
	}

	/// <summary>  
	/// 执行指定数据库事务的命令,映射数据表并填充数据集,指定存储过程参数值.  
	/// </summary>  
	/// <remarks>  
	/// 此方法不提供访问存储过程输出参数和返回值参数.  
	///
	/// 示例:    
	///  FillDataset(trans, "GetOrders", ds, new string[]{"orders"}, 24, 36);  
	/// </remarks>  
	/// <param>一个有效的连接事务</param>  
	/// <param>存储过程名称</param>  
	/// <param>要填充结果集的DataSet实例</param>  
	/// <param>表映射的数据表数组  
	/// 用户定义的表名 (可有是实际的表名.)  
	/// </param>  
	/// <param>分配给存储过程输入参数的对象数组</param>  
	public static void FillDataset(SqlTransaction transaction, string spName, DataSet dataSet, string[] tableNames, params object[] parameterValues)
	{
		if (transaction == null)
		{
			throw new ArgumentNullException("transaction");
		}
		if (transaction != null && transaction.Connection == null)
		{
			throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");
		}
		if (dataSet == null)
		{
			throw new ArgumentNullException("dataSet");
		}
		if (spName == null || spName.Length == 0)
		{
			throw new ArgumentNullException("spName");
		}
		if (parameterValues != null && parameterValues.Length != 0)
		{
			SqlParameter[] spParameterSet = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection, spName);
			AssignParameterValues(spParameterSet, parameterValues);
			FillDataset(transaction, CommandType.StoredProcedure, spName, dataSet, tableNames, spParameterSet);
		}
		else
		{
			FillDataset(transaction, CommandType.StoredProcedure, spName, dataSet, tableNames);
		}
	}

	/// <summary>  
	/// [私有方法][内部调用]执行指定数据库连接对象/事务的命令,映射数据表并填充数据集,DataSet/TableNames/SqlParameters.  
	/// </summary>  
	/// <remarks>  
	/// 示例:    
	///  FillDataset(conn, trans, CommandType.StoredProcedure, "GetOrders", ds, new string[] {"orders"}, new SqlParameter("@prodid", 24));  
	/// </remarks>  
	/// <param>一个有效的数据库连接对象</param>  
	/// <param>一个有效的连接事务</param>  
	/// <param>命令类型 (存储过程,命令文本或其它)</param>  
	/// <param>存储过程名称或T-SQL语句</param>  
	/// <param>要填充结果集的DataSet实例</param>  
	/// <param>表映射的数据表数组  
	/// 用户定义的表名 (可有是实际的表名.)  
	/// </param>  
	/// <param>分配给命令的SqlParamter参数数组</param>  
	private static void FillDataset(SqlConnection connection, SqlTransaction transaction, CommandType commandType, string commandText, DataSet dataSet, string[] tableNames, params SqlParameter[] commandParameters)
	{
		if (connection == null)
		{
			throw new ArgumentNullException("connection");
		}
		if (dataSet == null)
		{
			throw new ArgumentNullException("dataSet");
		}
		SqlCommand sqlCommand = new SqlCommand();
		bool mustCloseConnection = false;
		PrepareCommand(sqlCommand, connection, transaction, commandType, commandText, commandParameters, out mustCloseConnection);
		using (SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand))
		{
			if (tableNames != null && tableNames.Length != 0)
			{
				string text = "Table";
				for (int i = 0; i < tableNames.Length; i++)
				{
					if (tableNames[i] == null || tableNames[i].Length == 0)
					{
						throw new ArgumentException("The tableNames parameter must contain a list of tables, a value was provided as null or empty string.", "tableNames");
					}
					sqlDataAdapter.TableMappings.Add(text, tableNames[i]);
					text += i + 1;
				}
			}
			sqlDataAdapter.Fill(dataSet);
			sqlCommand.Parameters.Clear();
		}
		if (mustCloseConnection)
		{
			connection.Close();
		}
	}

	/// <summary>  
	/// 执行数据集更新到数据库,指定inserted, updated, or deleted命令.  
	/// </summary>  
	/// <remarks>  
	/// 示例:    
	///  UpdateDataset(conn, insertCommand, deleteCommand, updateCommand, dataSet, "Order");  
	/// </remarks>  
	/// <param>[追加记录]一个有效的T-SQL语句或存储过程</param>  
	/// <param>[删除记录]一个有效的T-SQL语句或存储过程</param>  
	/// <param>[更新记录]一个有效的T-SQL语句或存储过程</param>  
	/// <param>要更新到数据库的DataSet</param>  
	/// <param>要更新到数据库的DataTable</param>  
	public static void UpdateDataset(SqlCommand insertCommand, SqlCommand deleteCommand, SqlCommand updateCommand, DataSet dataSet, string tableName)
	{
		if (insertCommand == null)
		{
			throw new ArgumentNullException("insertCommand");
		}
		if (deleteCommand == null)
		{
			throw new ArgumentNullException("deleteCommand");
		}
		if (updateCommand == null)
		{
			throw new ArgumentNullException("updateCommand");
		}
		if (tableName == null || tableName.Length == 0)
		{
			throw new ArgumentNullException("tableName");
		}
		using SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
		sqlDataAdapter.UpdateCommand = updateCommand;
		sqlDataAdapter.InsertCommand = insertCommand;
		sqlDataAdapter.DeleteCommand = deleteCommand;
		sqlDataAdapter.Update(dataSet, tableName);
		dataSet.AcceptChanges();
	}

	/// <summary>  
	/// 创建SqlCommand命令,指定数据库连接对象,存储过程名和参数.  
	/// </summary>  
	/// <remarks>  
	/// 示例:    
	///  SqlCommand command = CreateCommand(conn, "AddCustomer", "CustomerID", "CustomerName");  
	/// </remarks>  
	/// <param>一个有效的数据库连接对象</param>  
	/// <param>存储过程名称</param>  
	/// <param>源表的列名称数组</param>  
	/// <returns>返回SqlCommand命令</returns>  
	public static SqlCommand CreateCommand(SqlConnection connection, string spName, params string[] sourceColumns)
	{
		if (connection == null)
		{
			throw new ArgumentNullException("connection");
		}
		if (spName == null || spName.Length == 0)
		{
			throw new ArgumentNullException("spName");
		}
		SqlCommand sqlCommand = new SqlCommand(spName, connection);
		sqlCommand.CommandType = CommandType.StoredProcedure;
		if (sourceColumns != null && sourceColumns.Length != 0)
		{
			SqlParameter[] spParameterSet = SqlHelperParameterCache.GetSpParameterSet(connection, spName);
			for (int i = 0; i < sourceColumns.Length; i++)
			{
				spParameterSet[i].SourceColumn = sourceColumns[i];
			}
			AttachParameters(sqlCommand, spParameterSet);
		}
		return sqlCommand;
	}

	/// <summary>  
	/// 执行指定连接数据库连接字符串的存储过程,使用DataRow做为参数值,返回受影响的行数.  
	/// </summary>  
	/// <param>一个有效的数据库连接字符串</param>  
	/// <param>存储过程名称</param>  
	/// <param>使用DataRow作为参数值</param>  
	/// <returns>返回影响的行数</returns>  
	public static int ExecuteNonQueryTypedParams(string connectionString, string spName, DataRow dataRow)
	{
		if (connectionString == null || connectionString.Length == 0)
		{
			throw new ArgumentNullException("connectionString");
		}
		if (spName == null || spName.Length == 0)
		{
			throw new ArgumentNullException("spName");
		}
		if (dataRow != null && dataRow.ItemArray.Length != 0)
		{
			SqlParameter[] spParameterSet = SqlHelperParameterCache.GetSpParameterSet(connectionString, spName);
			AssignParameterValues(spParameterSet, dataRow);
			return ExecuteNonQuery(connectionString, CommandType.StoredProcedure, spName, spParameterSet);
		}
		return ExecuteNonQuery(connectionString, CommandType.StoredProcedure, spName);
	}

	/// <summary>  
	/// 执行指定连接数据库连接对象的存储过程,使用DataRow做为参数值,返回受影响的行数.  
	/// </summary>  
	/// <param>一个有效的数据库连接对象</param>  
	/// <param>存储过程名称</param>  
	/// <param>使用DataRow作为参数值</param>  
	/// <returns>返回影响的行数</returns>  
	public static int ExecuteNonQueryTypedParams(SqlConnection connection, string spName, DataRow dataRow)
	{
		if (connection == null)
		{
			throw new ArgumentNullException("connection");
		}
		if (spName == null || spName.Length == 0)
		{
			throw new ArgumentNullException("spName");
		}
		if (dataRow != null && dataRow.ItemArray.Length != 0)
		{
			SqlParameter[] spParameterSet = SqlHelperParameterCache.GetSpParameterSet(connection, spName);
			AssignParameterValues(spParameterSet, dataRow);
			return ExecuteNonQuery(connection, CommandType.StoredProcedure, spName, spParameterSet);
		}
		return ExecuteNonQuery(connection, CommandType.StoredProcedure, spName);
	}

	/// <summary>  
	/// 执行指定连接数据库事物的存储过程,使用DataRow做为参数值,返回受影响的行数.  
	/// </summary>  
	/// <param>一个有效的连接事务 object</param>  
	/// <param>存储过程名称</param>  
	/// <param>使用DataRow作为参数值</param>  
	/// <returns>返回影响的行数</returns>  
	public static int ExecuteNonQueryTypedParams(SqlTransaction transaction, string spName, DataRow dataRow)
	{
		if (transaction == null)
		{
			throw new ArgumentNullException("transaction");
		}
		if (transaction != null && transaction.Connection == null)
		{
			throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");
		}
		if (spName == null || spName.Length == 0)
		{
			throw new ArgumentNullException("spName");
		}
		if (dataRow != null && dataRow.ItemArray.Length != 0)
		{
			SqlParameter[] spParameterSet = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection, spName);
			AssignParameterValues(spParameterSet, dataRow);
			return ExecuteNonQuery(transaction, CommandType.StoredProcedure, spName, spParameterSet);
		}
		return ExecuteNonQuery(transaction, CommandType.StoredProcedure, spName);
	}

	/// <summary>  
	/// 执行指定连接数据库连接字符串的存储过程,使用DataRow做为参数值,返回DataSet.  
	/// </summary>  
	/// <param>一个有效的数据库连接字符串</param>  
	/// <param>存储过程名称</param>  
	/// <param>使用DataRow作为参数值</param>  
	/// <returns>返回一个包含结果集的DataSet.</returns>  
	public static DataSet ExecuteDatasetTypedParams(string connectionString, string spName, DataRow dataRow)
	{
		if (connectionString == null || connectionString.Length == 0)
		{
			throw new ArgumentNullException("connectionString");
		}
		if (spName == null || spName.Length == 0)
		{
			throw new ArgumentNullException("spName");
		}
		if (dataRow != null && dataRow.ItemArray.Length != 0)
		{
			SqlParameter[] spParameterSet = SqlHelperParameterCache.GetSpParameterSet(connectionString, spName);
			AssignParameterValues(spParameterSet, dataRow);
			return ExecuteDataset(connectionString, CommandType.StoredProcedure, spName, spParameterSet);
		}
		return ExecuteDataset(connectionString, CommandType.StoredProcedure, spName);
	}

	/// <summary>  
	/// 执行指定连接数据库连接对象的存储过程,使用DataRow做为参数值,返回DataSet.  
	/// </summary>  
	/// <param>一个有效的数据库连接对象</param>  
	/// <param>存储过程名称</param>  
	/// <param>使用DataRow作为参数值</param>  
	/// <returns>返回一个包含结果集的DataSet.</returns>  
	public static DataSet ExecuteDatasetTypedParams(SqlConnection connection, string spName, DataRow dataRow)
	{
		if (connection == null)
		{
			throw new ArgumentNullException("connection");
		}
		if (spName == null || spName.Length == 0)
		{
			throw new ArgumentNullException("spName");
		}
		if (dataRow != null && dataRow.ItemArray.Length != 0)
		{
			SqlParameter[] spParameterSet = SqlHelperParameterCache.GetSpParameterSet(connection, spName);
			AssignParameterValues(spParameterSet, dataRow);
			return ExecuteDataset(connection, CommandType.StoredProcedure, spName, spParameterSet);
		}
		return ExecuteDataset(connection, CommandType.StoredProcedure, spName);
	}

	/// <summary>  
	/// 执行指定连接数据库事务的存储过程,使用DataRow做为参数值,返回DataSet.  
	/// </summary>  
	/// <param>一个有效的连接事务 object</param>  
	/// <param>存储过程名称</param>  
	/// <param>使用DataRow作为参数值</param>  
	/// <returns>返回一个包含结果集的DataSet.</returns>  
	public static DataSet ExecuteDatasetTypedParams(SqlTransaction transaction, string spName, DataRow dataRow)
	{
		if (transaction == null)
		{
			throw new ArgumentNullException("transaction");
		}
		if (transaction != null && transaction.Connection == null)
		{
			throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");
		}
		if (spName == null || spName.Length == 0)
		{
			throw new ArgumentNullException("spName");
		}
		if (dataRow != null && dataRow.ItemArray.Length != 0)
		{
			SqlParameter[] spParameterSet = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection, spName);
			AssignParameterValues(spParameterSet, dataRow);
			return ExecuteDataset(transaction, CommandType.StoredProcedure, spName, spParameterSet);
		}
		return ExecuteDataset(transaction, CommandType.StoredProcedure, spName);
	}

	/// <summary>  
	/// 执行指定连接数据库连接字符串的存储过程,使用DataRow做为参数值,返回DataReader.  
	/// </summary>  
	/// <param>一个有效的数据库连接字符串</param>  
	/// <param>存储过程名称</param>  
	/// <param>使用DataRow作为参数值</param>  
	/// <returns>返回包含结果集的SqlDataReader</returns>  
	public static SqlDataReader ExecuteReaderTypedParams(string connectionString, string spName, DataRow dataRow)
	{
		if (connectionString == null || connectionString.Length == 0)
		{
			throw new ArgumentNullException("connectionString");
		}
		if (spName == null || spName.Length == 0)
		{
			throw new ArgumentNullException("spName");
		}
		if (dataRow != null && dataRow.ItemArray.Length != 0)
		{
			SqlParameter[] spParameterSet = SqlHelperParameterCache.GetSpParameterSet(connectionString, spName);
			AssignParameterValues(spParameterSet, dataRow);
			return ExecuteReader(connectionString, CommandType.StoredProcedure, spName, spParameterSet);
		}
		return ExecuteReader(connectionString, CommandType.StoredProcedure, spName);
	}

	/// <summary>  
	/// 执行指定连接数据库连接对象的存储过程,使用DataRow做为参数值,返回DataReader.  
	/// </summary>  
	/// <param>一个有效的数据库连接对象</param>  
	/// <param>存储过程名称</param>  
	/// <param>使用DataRow作为参数值</param>  
	/// <returns>返回包含结果集的SqlDataReader</returns>  
	public static SqlDataReader ExecuteReaderTypedParams(SqlConnection connection, string spName, DataRow dataRow)
	{
		if (connection == null)
		{
			throw new ArgumentNullException("connection");
		}
		if (spName == null || spName.Length == 0)
		{
			throw new ArgumentNullException("spName");
		}
		if (dataRow != null && dataRow.ItemArray.Length != 0)
		{
			SqlParameter[] spParameterSet = SqlHelperParameterCache.GetSpParameterSet(connection, spName);
			AssignParameterValues(spParameterSet, dataRow);
			return ExecuteReader(connection, CommandType.StoredProcedure, spName, spParameterSet);
		}
		return ExecuteReader(connection, CommandType.StoredProcedure, spName);
	}

	/// <summary>  
	/// 执行指定连接数据库事物的存储过程,使用DataRow做为参数值,返回DataReader.  
	/// </summary>  
	/// <param>一个有效的连接事务 object</param>  
	/// <param>存储过程名称</param>  
	/// <param>使用DataRow作为参数值</param>  
	/// <returns>返回包含结果集的SqlDataReader</returns>  
	public static SqlDataReader ExecuteReaderTypedParams(SqlTransaction transaction, string spName, DataRow dataRow)
	{
		if (transaction == null)
		{
			throw new ArgumentNullException("transaction");
		}
		if (transaction != null && transaction.Connection == null)
		{
			throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");
		}
		if (spName == null || spName.Length == 0)
		{
			throw new ArgumentNullException("spName");
		}
		if (dataRow != null && dataRow.ItemArray.Length != 0)
		{
			SqlParameter[] spParameterSet = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection, spName);
			AssignParameterValues(spParameterSet, dataRow);
			return ExecuteReader(transaction, CommandType.StoredProcedure, spName, spParameterSet);
		}
		return ExecuteReader(transaction, CommandType.StoredProcedure, spName);
	}

	/// <summary>  
	/// 执行指定连接数据库连接字符串的存储过程,使用DataRow做为参数值,返回结果集中的第一行第一列.  
	/// </summary>  
	/// <param>一个有效的数据库连接字符串</param>  
	/// <param>存储过程名称</param>  
	/// <param>使用DataRow作为参数值</param>  
	/// <returns>返回结果集中的第一行第一列</returns>  
	public static object ExecuteScalarTypedParams(string connectionString, string spName, DataRow dataRow)
	{
		if (connectionString == null || connectionString.Length == 0)
		{
			throw new ArgumentNullException("connectionString");
		}
		if (spName == null || spName.Length == 0)
		{
			throw new ArgumentNullException("spName");
		}
		if (dataRow != null && dataRow.ItemArray.Length != 0)
		{
			SqlParameter[] spParameterSet = SqlHelperParameterCache.GetSpParameterSet(connectionString, spName);
			AssignParameterValues(spParameterSet, dataRow);
			return ExecuteScalar(connectionString, CommandType.StoredProcedure, spName, spParameterSet);
		}
		return ExecuteScalar(connectionString, CommandType.StoredProcedure, spName);
	}

	/// <summary>  
	/// 执行指定连接数据库连接对象的存储过程,使用DataRow做为参数值,返回结果集中的第一行第一列.  
	/// </summary>  
	/// <param>一个有效的数据库连接对象</param>  
	/// <param>存储过程名称</param>  
	/// <param>使用DataRow作为参数值</param>  
	/// <returns>返回结果集中的第一行第一列</returns>  
	public static object ExecuteScalarTypedParams(SqlConnection connection, string spName, DataRow dataRow)
	{
		if (connection == null)
		{
			throw new ArgumentNullException("connection");
		}
		if (spName == null || spName.Length == 0)
		{
			throw new ArgumentNullException("spName");
		}
		if (dataRow != null && dataRow.ItemArray.Length != 0)
		{
			SqlParameter[] spParameterSet = SqlHelperParameterCache.GetSpParameterSet(connection, spName);
			AssignParameterValues(spParameterSet, dataRow);
			return ExecuteScalar(connection, CommandType.StoredProcedure, spName, spParameterSet);
		}
		return ExecuteScalar(connection, CommandType.StoredProcedure, spName);
	}

	/// <summary>  
	/// 执行指定连接数据库事务的存储过程,使用DataRow做为参数值,返回结果集中的第一行第一列.  
	/// </summary>  
	/// <param>一个有效的连接事务 object</param>  
	/// <param>存储过程名称</param>  
	/// <param>使用DataRow作为参数值</param>  
	/// <returns>返回结果集中的第一行第一列</returns>  
	public static object ExecuteScalarTypedParams(SqlTransaction transaction, string spName, DataRow dataRow)
	{
		if (transaction == null)
		{
			throw new ArgumentNullException("transaction");
		}
		if (transaction != null && transaction.Connection == null)
		{
			throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");
		}
		if (spName == null || spName.Length == 0)
		{
			throw new ArgumentNullException("spName");
		}
		if (dataRow != null && dataRow.ItemArray.Length != 0)
		{
			SqlParameter[] spParameterSet = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection, spName);
			AssignParameterValues(spParameterSet, dataRow);
			return ExecuteScalar(transaction, CommandType.StoredProcedure, spName, spParameterSet);
		}
		return ExecuteScalar(transaction, CommandType.StoredProcedure, spName);
	}

	/// <summary>  
	/// 执行指定连接数据库连接对象的存储过程,使用DataRow做为参数值,返回XmlReader类型的结果集.  
	/// </summary>  
	/// <param>一个有效的数据库连接对象</param>  
	/// <param>存储过程名称</param>  
	/// <param>使用DataRow作为参数值</param>  
	/// <returns>返回XmlReader结果集对象.</returns>  
	public static XmlReader ExecuteXmlReaderTypedParams(SqlConnection connection, string spName, DataRow dataRow)
	{
		if (connection == null)
		{
			throw new ArgumentNullException("connection");
		}
		if (spName == null || spName.Length == 0)
		{
			throw new ArgumentNullException("spName");
		}
		if (dataRow != null && dataRow.ItemArray.Length != 0)
		{
			SqlParameter[] spParameterSet = SqlHelperParameterCache.GetSpParameterSet(connection, spName);
			AssignParameterValues(spParameterSet, dataRow);
			return ExecuteXmlReader(connection, CommandType.StoredProcedure, spName, spParameterSet);
		}
		return ExecuteXmlReader(connection, CommandType.StoredProcedure, spName);
	}

	/// <summary>  
	/// 执行指定连接数据库事务的存储过程,使用DataRow做为参数值,返回XmlReader类型的结果集.  
	/// </summary>  
	/// <param>一个有效的连接事务 object</param>  
	/// <param>存储过程名称</param>  
	/// <param>使用DataRow作为参数值</param>  
	/// <returns>返回XmlReader结果集对象.</returns>  
	public static XmlReader ExecuteXmlReaderTypedParams(SqlTransaction transaction, string spName, DataRow dataRow)
	{
		if (transaction == null)
		{
			throw new ArgumentNullException("transaction");
		}
		if (transaction != null && transaction.Connection == null)
		{
			throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");
		}
		if (spName == null || spName.Length == 0)
		{
			throw new ArgumentNullException("spName");
		}
		if (dataRow != null && dataRow.ItemArray.Length != 0)
		{
			SqlParameter[] spParameterSet = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection, spName);
			AssignParameterValues(spParameterSet, dataRow);
			return ExecuteXmlReader(transaction, CommandType.StoredProcedure, spName, spParameterSet);
		}
		return ExecuteXmlReader(transaction, CommandType.StoredProcedure, spName);
	}
}
